using UnityEngine;

namespace Gameplay.PVE
{
    public class DragAction : SpecialActionBase
    {
        private float startTime;
        private float speed = 0.3f;
        private float accelerate = 1;
        private float accelerateVertical = 1;
        private float actionDuration;
        private Vector3 forward;

        public override void Start(AddControlArg arg)
        {
            base.Start(arg);
            startTime = TimeManager.logicTime;
            arg.forward.y = 0;
            forward = arg.forward;
            actionDuration = arg.time;
            accelerate = -arg.distance * 2 / actionDuration / actionDuration;
            speed = -accelerate * actionDuration;
        }
        
        public override void Update()
        {
            if (state == ESpecialActionState.Playing && TimeManager.logicTime - startTime < actionDuration)
            {
                var position = unit.Data.position + speed * TimeManager.LogicDeltaTime * forward;
                //if (PveFindPathManager.Instance.CheckIsWalkable(position, unit.Data.id))
                {
                    unit.Data.position = position;
                }
                speed += accelerate * TimeManager.LogicDeltaTime;
            }
            else
            {
                //unit.Data.position.y = 0;
                //state = ESpecialActionState.None;
            }
        }
    }
}